package visualisation;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;

import demo.RobotCommunication;

public class MainWindow extends JPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	JMenuBar menuBar;
	JMenu fileMenu, OptionsMenu, helpMenu;
	JMenuItem menuItem;
	
	static JFrame frame = new JFrame("Robot Communication DEMO");
	
	public MainWindow() {
		super(new BorderLayout());
		menuBar = new JMenuBar();
		frame.setJMenuBar(menuBar);
		
		fileMenu = new JMenu("File");
		fileMenu.add(menuItem = new JMenuItem("Exit"));
		menuItem.addActionListener(new ActionListener() {
	      public void actionPerformed(ActionEvent e) {
	        System.exit(0);
	      }
	    });
		menuBar.add(fileMenu);
		
		OptionsMenu = new JMenu("Demo");
		OptionsMenu.add(menuItem = new JMenuItem("Start"));
	    ActionListener insertionSortHandler  = new ActionListener() {
	        public void actionPerformed(ActionEvent e) {
	        	//enable demo
	        	String[] args = null;
	        	try {
					@SuppressWarnings("unused")
					RobotCommunication demo = new RobotCommunication(args, getGraphics());
				} catch (Exception e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
	        }
	    };
	    menuItem.addActionListener(insertionSortHandler );
	    menuBar.add(OptionsMenu);
	    
	    helpMenu = new JMenu("Help");
	    helpMenu.add(menuItem = new JMenuItem("Test"));
	    ActionListener insertionSortHandler2 = new ActionListener() {
	    	public void actionPerformed(ActionEvent e) {
	    		//enable test data
	    		SimulationData sim = new SimulationData(getGraphics());
	    		sim.putNodes();
	    		sim.moveRobot();
	    		sim.dessin.drawTrajectory();
	    	}
	    };
	    menuItem.addActionListener(insertionSortHandler2);
	    menuBar.add(helpMenu);
	}
	
	public static void createAndShowGUI() {
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		JComponent newContentPane =  new MainWindow();
		
		newContentPane.setOpaque(true);
		frame.setContentPane(newContentPane);
		
		newContentPane.setMinimumSize(new Dimension(newContentPane.getPreferredSize().width, 1000));
		frame.setBounds(30,30,500,500);
		newContentPane.setAutoscrolls(true);
		
		frame.setVisible(true);
	}
	
	public static void main(String[] args) {
		MainWindow.createAndShowGUI();
		/*
		javax.swing.SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				MainWindow.createAndShowGUI();
			}
		});*/
	}

}
